-
Notifications
You must be signed in to change notification settings - Fork 3.6k
code optimization #2032
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: dev
Are you sure you want to change the base?
code optimization #2032
Conversation
I am not sure if this produces the same result (I didn't spend time much :). I will consider this later since it has not an important enhancement. |
|
.FirstOrDefault(i => i.GetTypeInfo().IsGenericType && | ||
i.GetGenericTypeDefinition() == typeof(IServiceProviderFactory<>)); | ||
|
||
if (factoryInterface == null) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You can't use var when reassigning to an existing variable
if (factoryInterface == null)
factoryInterface = service.ServiceType;
if (factoryInterface == null ||
!factoryInterface.IsGenericType ||
factoryInterface.GetGenericTypeDefinition() != typeof(IServiceProviderFactory<>))
{
// handle error or return
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
var factoryInterface = service.ImplementationInstance?.GetType()
.GetInterfaces()
.FirstOrDefault(i => i.IsGenericType &&
i.GetGenericTypeDefinition() == typeof(IServiceProviderFactory<>));
Removed var - Should be a simple assignment since factoryInterface is already declared
Removed GetTypeInfo() - Direct access to GetGenericTypeDefinition() in latest .NET
Now that the following code:
requires 'IServiceProviderFactory' Service Type,
For intuition and efficiency, my code may be better. And strickly saying, they are not of equal value. If registered service type 'XxxServiceProviderFactory', the former code may
throw AbpException($"Could not find {typeof(IServiceProviderFactory<TContainerBuilder>).FullName} in {services}.")
, my code won't.It will just return 'services.BuildServiceProvider()'.